package cn.jiyun.ai.impl;

import cn.jiyun.ai.QuestionService;
import cn.jiyun.ai.common.Result;
import cn.jiyun.ai.mapper.QuestionMapper;
import cn.jiyun.ai.pojo.Question;
import cn.jiyun.ai.pojo.vo.QuestionReqSearchVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> implements QuestionService {
    @Autowired
    QuestionMapper questionMapper;

    @Override
    public Result findQuestionList(QuestionReqSearchVo questionReqSearchVo) {
        QueryWrapper<Question> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(questionReqSearchVo.getType()!=null&&questionReqSearchVo.getType()!=99,Question::getType,questionReqSearchVo.getType());
        List<Question> questionList = questionMapper.selectList(queryWrapper);
        return Result.ok(questionList);
    }

    @Override
    public Result selectQuestionById(Integer id) {
        QueryWrapper<Question> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Question::getId,id);
        Question question = questionMapper.selectOne(queryWrapper);
        question.setSearchCount(question.getSearchCount()+1);
        questionMapper.updateById(question);
        return Result.ok(question);
    }
}
